<template>
    <div class="home">
        <div class="header">
            <div class="card">
                <div class="content">
                    <div class="label">用户总数</div>
                    <div class="value">12458</div>
                    <div class="compare">
                        <span class="percent">+15.8%</span>
                        <span class="time">较上月</span>
                    </div>
                </div>
                <img class="icon" />
            </div>
            <div class="card">
                <div class="content">
                    <div class="label">订单总数</div>
                    <div class="value">12458</div>
                    <div class="compare">
                        <span class="percent">+15.8%</span>
                        <span class="time">较上月</span>
                    </div>
                </div>
                <img class="icon" />
            </div>
            <div class="card">
                <div class="content">
                    <div class="label">课程总数</div>
                    <div class="value">12458</div>
                    <div class="compare">
                        <span class="percent">+15.8%</span>
                        <span class="time">较上月</span>
                    </div>
                </div>
                <img class="icon" />
            </div>
        </div>
        <div class="user-chart">
            <div class="title">
                <div class="label">用户增长趋势</div>
                <el-select v-model="date" style="width: 200px;">
                    <el-option label="近7天" value="week"></el-option>
                </el-select>
            </div>
            <div id="user-chart" class="chart"></div>
        </div>
    </div>
</template>

<script>
import * as echarts from "echarts";
export default {
    data() {
        return {
            date: "week",
            userChart: null
        }
    },
    mounted() {
        this.initUserChart();
    },
    methods: {
        initUserChart() {
            if (this.userChart) {
                this.userChart.dispose();
                this.userChart = null;
            }
            this.userChart = echarts.init(document.getElementById("user-chart"));
            let option = {
                tooltip: {
                    trigger: "axis"
                },
                grid: {
                    left: "3%",
                    right: "4%",
                    bottom: "3%",
                    containLabel: true
                },
                xAxis: {
                    type: "category",
                    boundaryGap: false,
                    data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
                },
                yAxis: {
                    type: "value"
                },
                series: [
                    {
                        name: "新增用户",
                        type: "line",
                        smooth: true,
                        data: [120, 132, 101, 134, 90, 230, 210],
                        areaStyle: {}
                    }
                ]
            };
            this.userChart.setOption(option);
        },
    }
}
</script>

<style lang="scss" scoped>
.home {
    height: 100%;
    background: #F9FAFB;
    padding: 40px;

    .header {
        display: flex;
        gap: 24px;
        margin-bottom: 32px;

        .card {
            display: flex;
            justify-content: space-between;
            flex: 1 0 0%;
            background: #fff;
            box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.05);
            border-radius: 8px;
            padding: 20px;

            .icon {
                display: block;
                width: 53px;
                height: 53px;
                border-radius: 50%;
            }

            .content {
                .label {
                    font-weight: 500;
                    font-size: 14px;
                    color: #6B7280;
                }

                .value {
                    font-size: 24px;
                    font-weight: 600;
                    color: #000000;
                    margin-top: 8px;
                    margin-bottom: 16px;
                }

                .compare {

                    .percent {
                        font-weight: 500;
                        font-size: 14px;
                        color: #16A34A;
                    }

                    .time {
                        font-weight: 500;
                        font-size: 14px;
                        color: #6B7280;
                        margin-left: 10px;
                    }
                }
            }
        }
    }

    .user-chart {
        padding: 20px;
        background: #fff;
        box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.05);
        border-radius: 8px;

        .title {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;

            .label {
                font-size: 18px;
                font-weight: 500;
                color: #000000;
            }
        }

        .chart {
            height: 400px;
        }
    }
}
</style>